/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 * Version：V1.0.2(20230701).
 */
package top.hiai._admin.auth;

import top.hiai.common.model.User;
/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top
* @Introduction 类的介绍
*/

public class AdminAuthKit {
	/**
	 * 当前账号是否拥有某些角色
	 */
	public boolean hasRole(String... roleNameArray) {
		User account = AdminAuthInterceptor.getThreadLocalAccount();
		if (account != null && account.isStatusOk()) {
			if (	AdminAuthService.me.isSuperAdmin(account.getUid()) ||
					AdminAuthService.me.hasRole(account.getUid(), roleNameArray)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 是否拥有具体某个权限
	 */
	public boolean hasPermission(String actionKey) {
		User account = AdminAuthInterceptor.getThreadLocalAccount();
		if (account != null && account.isStatusOk()) {
			if (	AdminAuthService.me.isSuperAdmin(account.getUid()) ||
					AdminAuthService.me.hasPermission(account.getUid(), actionKey)) {
				return true;
			}
		}
		return false;
	}
}